using System.Web.Services;
using System.Web;
using System.Xml;
using System;
using umlungu.engineX.blogX;

/*	-----------------------------------------------------------------------	
	Copyright:	umlungu consulting (pty) ltd
	Author:		Alan Benington
	Started:	2007-05-19
	Status:		live	
	Version:	2.0.0
	Build:		20070519
	License:	GNU General Public License
	-----------------------------------------------------------------------	*/
	
/*	-----------------------------------------------------------------------	
	Development Notes:
	==================
	20070519:
	- Starting point.
	---------------------------------------------------------------------------	*/
	
namespace umlungu.engineX.blogX.TestSiteX {
	/// <summary>
	/// Description of the classX class.
	/// <para>Additional information about the class</para>
	/// </summary>
	public class TestSiteDisplayX : displayX {
		#region Invisible properties
		private x_broker broker;
		#endregion

		#region Visible properties
		private string property;
		/// <summary>Definiton of the property</summary>
		/// <value>Description of the value of the property</value>
		public string Property {
			get { return property; }
			set { property = value; }
		}
		#endregion

		#region Constructors/Destructors
		/// <summary>Default constructor</summary>
		public TestSiteDisplayX() : base("TestSite") {
		}
		/// <summary>Constructor for derived classes</summary>
		public TestSiteDisplayX(string label) : base(label) {
		}
		#endregion

		#region Public methods
		#endregion
		
		#region Protected methods
		/// <summary>
		/// Does the pre-processing of the page request. 
		///	This method is overriden in order to:
		///	- Add form fields to the profile
		/// </summary>
		protected override void _ProcessRequest() {
			UserProfile.Add(Request);
			switch (Parameters.Broker) {
				// Example broker
				case "example":			broker = new TestSiteExample(this);		broker.Process("test");	break;
				// Tests
				case "errortest":		throw new x_exception("error_test", "This is an error test");
				case null:
				case "":				break;
				// use base broker for default (ie sends email on submission)
				default:				broker = new x_broker(this);			broker.Process();	break;
			}
		}
		/// <summary>
		/// Does the post-processing of the page content. 
		///	This method is overriden in order to:
		///	- add feedback and login xml
		///	- post process the xml content through a broker (ie extend xml added via page.xml)
		/// </summary>
		protected override void _ProcessContent() {
			if (Parameters.YesNo("relinfo", true)) {
				XmlElement relEl = (XmlElement)Content.AppendChild(Document.CreateElement("relinfo"));
				if (Parameters.YesNo("feed"))	// ie off by default
					loadFeedBack(relEl);
				/*
				if (Parameters.YesNo("login"))	// ie off by default
					loadLogon(relEl);
				*/
			}
			switch (Parameters.Broker) {
				case "example":		((TestSiteExample)broker).ProcessContent(Content);	break;
			}
		}
		#endregion
				
		#region Private methods
		/// <summary>Load the feedback element</summary>
		private void loadFeedBack(XmlElement thisel) {
			TestSiteFeed thisfeed = new TestSiteFeed(Application);
			thisfeed.Add(Page, thisel);
			XmlNode lnkname = thisel.SelectSingleNode("feedback/page/fields/fld[@name='LinkName']/value");
			if (lnkname != null)
				lnkname.InnerText = Parameters.LinkName;
		}
		/// <summary>Load the login element</summary>
		private void loadLogon(XmlElement thisel) {
			TestSiteLogon thislogon = new TestSiteLogon(Application);
			thislogon.Add(Page, thisel);
		}
		#endregion
	}
}
